package com.guigu.www.service.imp;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.guigu.www.mapper.AuthorizationMapper;
import com.guigu.www.mapper.RoleAuthorizationMapper;
import com.guigu.www.mapper.RolesMapper;
import com.guigu.www.pojo.Authorization;
import com.guigu.www.pojo.RoleAuthorization;
import com.guigu.www.pojo.Roles;
import com.guigu.www.service.RoleAuthorizationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class RoleAuthorizationServiceImpl extends ServiceImpl<RoleAuthorizationMapper,RoleAuthorization> implements RoleAuthorizationService {
    //创建mapper
    @Autowired
    RoleAuthorizationMapper mapper;
    @Autowired
    RolesMapper rolesmapper;
    @Autowired
    AuthorizationMapper authorizationMapper;
    @Override
    public List<Authorization> addquanxian(int roleid) {
        List<Authorization> rolesList=authorizationMapper.querybyauall();
        List<Authorization> roles=authorizationMapper.querybyroleid(roleid);
        for(Authorization role:rolesList){
            for(Authorization roles1 : roles){
                if(role.getAuid()==roles1.getAuid()){
                    role.setCheck(true);
                }
            }
        }
        return rolesList;
    }

    @Override
    public void addquanxian2(Roles roles) {
        mapper.deletera(roles.getId());
        for(Authorization authorization : roles.getAuthorizationList()){
            RoleAuthorization roleAuthorization=new RoleAuthorization();
            roleAuthorization.setId(roles.getId());
            roleAuthorization.setAuid(authorization.getAuid());
            mapper.addquanxian(roleAuthorization);
        }
    }
}
